# # 条形图
# # 为图表创建数据
# H <- c(7, 12, 28, 3, 41)
# # 设置文件名
# png(file = "barchart.png")
# # 绘制图表
# barplot(H)
# # 保存图片
# dev.off()

# # 条形图标签，标题和颜色
# # 为图表创建数据
# H <- c(7, 12, 28, 3, 41)
# M <- c("Mar", "Apr", "May", "Jun", "Jul")
# # 设置文件名
# png(file = "barchart_months_revenue.png")
# # 绘制图表
# barplot(H, names.arg = M, xlab = "Month", ylab = "Revenue", col = "blue", main = "Revenue chart", border = "red")
# # 保存文件
# dev.off()

# # 组合条形图和堆积条形图
# # 创建输入向量
# colors <- c("green", "orange", "brown")
# months <- c("Mar", "Apr", "May", "Jun", "Jul")
# regions <- c("East", "West", "North")
# # 创建数据矩阵
# values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11), nrow = 3, ncol = 5, byrow = TRUE)
# # 设置文件名
# png(file = "barchart_stacked.png")
# # 创建条形图
# barplot(values, main = "total revenue", names.arg = months, xlab = "month", ylab = "revenue", col = colors)
# # 添加图例
# legend("topleft", regions, cex = 1.3, fill = colors)
# # 保存文件
# dev.off()

# 箱线图
# # 打印数据集
# input <- mtcars[, c('mpg', 'cyl')]
# print(input)

# 创建箱线图
# # 设置文件名
# png(file = "boxplot.png")
# # 绘制图表
# boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of Cylinders", ylab = "Miles Per Gallon", main = "Mileage Data")
# # 保存文件
# dev.off()

# 带槽的箱线图
# # 设置文件名
# png(file = "boxplot_with_notch.png")
# # 绘制图表
# boxplot(mpg ~ cyl, data = mtcars,
# 	xlab = "Number of Cylinders",
# 	ylab = "Miles Per Gallon", 
# 	main = "Mileage Data",
# 	notch = TRUE,
# 	varwidth = TRUE,
# 	col = c("green", "yellow", "purple"),
# 	names = c("Hign", "Medium", "Low")
# )
# # 保存文件
# dev.off()

# 直方图
# # 创建直方图
# # 创建向量
# v <- c(9, 13, 21, 8, 36, 22, 12, 41, 31, 33, 19)
# # 设置文件名
# png(file = "histogram.png")
# # 创建直方图
# hist(v, xlab = "Weight", col = "yellow", border = "blue")
# # 保存文件
# dev.off()

# X和Y值的范围
# # 创建向量
# v <- c(9, 13, 21, 8, 36, 22, 12, 41, 31, 33, 19)
# # 设置文件名
# png(file = "histogram_lim_breaks.png")
# # 创建直方图
# hist(v, xlab = "Weight", col = "green", border = "red", xlim = c(0, 50), ylim = c(0, 5), breaks = 4)
# # 保存文件
# dev.off()

# 折线图
# # 创建折线图
# # 创建图表数据
# v <- c(7, 12, 28, 3, 41)
# # 设置文件名
# png(file = "line_chart.png")
# # 绘制折线
# plot(v, type = "o")
# # 保存文件
# dev.off()

# 折线图标题，颜色和标签
# # 创建图表数据
# v <- c(7, 12, 28, 3, 41)
# # 设置文件名
# png(file = "line_chart_label_colored.png")
# # 绘制折线
# plot(v, type = "o", col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart")
# # 保存文件
# dev.off()

# 多线型折线图
# # 使用lines()函数，可以在同一个图表上绘制多条线
# # 创建图表数据
# v <- c(7, 12, 28, 3, 41)
# t <- c(14, 7, 6, 19, 3)
# # 设置文件名
# png(file = "line_chart_2_lines.png")
# # 绘制表
# plot(v, type = "o", col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart")
# lines(t, type = "o", col = "blue")
# # 保存文件
# dev.off()

# 散点图
# # 数据集
# input <- mtcars[, c('wt', 'mpg')]
# print(input)

# 创建散点图
# # 数据
# input <- mtcars[, c('wt', 'mpg')]
# # 设置文件名
# png(file = 'scatterplot.png')
# # 创建表
# plot(x = input$wt, y = input$mpg,
# 	xlab = "Weight",
# 	ylab = "Milage",
# 	xlim = c(2.5, 5),
# 	ylim = c(15, 30),
# 	main = "Weight vs Milage"
# )
# # 保存文件
# dev.off()

# 散点图矩阵--pairs()
# # 设置文件名
# png(file = "scatterplot_matrices.png")
# # 绘制
# pairs(~ wt + mpg + disp + cyl, data = mtcars, main = "Scatterplot Matrix")
# # 保存文件
# dev.off()

# # 饼状图
# x <- c(21, 62, 10, 53)
# labels <- c("London", "New York", "Singapore", "Mumbai")
# # 设置文件名
# png(file = "city.png")
# # 绘制饼图
# pie(x, labels)
# # 保存文件
# dev.off()

# 饼图标题和颜色
# # 数据
# x <- c(21, 62, 10, 53)
# labels <- c("London", "New York", "Singapore", "Mumbai")
# # 设置文件名
# png(file = "city_title_colors.png")
# # 绘制
# pie(x, labels, main = "City pie chart", col = rainbow(length(x)))
# # 保存文件
# dev.off()

# 切片百分比和图表图例
# # 数据
# x <- c(21, 62, 10, 53)
# labels <- c("London", "New York", "Singapore", "Mumbai")
# # 计算百分比
# piepercent <- round(100 * x / sum(x), 1)
# # 设置文件名
# png(file = "city_percentage_legends.png")
# # 绘制图表
# pie(x, labels = piepercent, main = "City pie chart", col = rainbow(length(x)))
# # 图例
# legend("topright", c("London", "New York", "Singapore", "Mumbai"), cex = 0.8, fill = rainbow(length(x)))
# # 保存文件
# dev.off()

# # 安装包
# install.packages("plotrix", repos="https://cran.cnr.berkeley.edu/")
# # 引入库
# library(plotrix)
# # 创建数据
# x <- c(21, 62, 10, 53)
# lbl <- c("London", "New York", "Singapore", "Mumbai")
# # 设置文件名
# png(file = "3d_pie_chart.png")
# # 绘制图表
# pie3D(x, labels = lbl, explode = 0.1, main = "Pie chart Of Countries")
# # 保存文件
# dev.off()

# # 引入库
# library(plotrix)
# # 创建数据
# x <- c(21, 62, 10, 53)
# lbl <- c("London", "New York", "Singapore", "Mumbai")
# # 设置文件名
# pdf(file = "3d_pie_chart.pdf")
# # 绘制图表
# pie3D(x, labels = lbl, explode = 0.1, main = "Pie chart Of Countries")
# # 保存文件
# dev.off()









